<!-- 登录日志 -->
<template>
  <div>
    <CommonSearch @search="query" @reset="reset">
      <el-col :span="8">
        <el-form-item label="用户名">
          <el-input
            v-model="queryParams.condition.accountName"
            clearable
            style="width: 100%"
          />
        </el-form-item>
      </el-col>
      <el-col :span="8">
        <el-form-item label="操作时间">
          <el-date-picker
            v-model="queryParams.condition.searchTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            style="width: 100%;height:32px;"
            @change="(date) => timeChange(date, queryParams.condition)"
          >
          </el-date-picker>
        </el-form-item>
      </el-col>
      <el-col :span="8">
        <el-form-item label="操作结果">
          <DictSelect
            v-model="queryParams.condition.operateType"
            :defaultOptions="options.operateType"
            placeholder="请选择"
            clearable
            style="width: 100%;"
          />
        </el-form-item>
      </el-col>
      <el-col :span="8">
        <el-form-item label="登录渠道">
          <DictSelect
            v-model="queryParams.condition.channel"
            :defaultOptions="options.channel"
            placeholder="请选择"
            clearable
            style="width: 100%;"
          />
        </el-form-item>
      </el-col>
    </CommonSearch>

    <el-row class="cardMiniBar">
      <el-col :span="24">
        <div class="fr">
          <!-- <el-button type="primary" @click="add" size="small">导出</el-button> -->
        </div>
      </el-col>
    </el-row>

    <div class="cardBody">
      <edu-table
        ref="mainTable"
        :data="tableList"
        :pageSize="queryParams.pageSize"
        :pageNum="queryParams.pageNum"
        :total="queryParams.total"
        @page-change="handleCurrentChange"
        :order="true"
        :selection="true"
      >
        <el-table-column label="用户ID" prop="accountId" width="130"/>
        <el-table-column label="用户名" prop="accountName"/>
        <el-table-column label="操作类型" width="110">
          <template slot-scope="scope">
            {{ renderOption(scope.row.operateType, "operateType") }}
          </template>
        </el-table-column>
        <el-table-column label="操作时间" prop="operateTime" width="160" />
        <el-table-column label="登录渠道" width="110">
          <template slot-scope="scope">
            {{ renderOption(scope.row.channel, "channel") }}
          </template>
        </el-table-column>
        <el-table-column label="登录终端" prop="terminal" width="160"/>
        <el-table-column label="ip" prop="ip" />
        <el-table-column label="版本" prop="version"/>
        <el-table-column label="操作" fixed="right" width="90px">
          <template slot-scope="scope">
            <el-button
              type="text"
              @click="view(scope.row)"
              size="small"
            >
              查看
            </el-button>
          </template>
        </el-table-column>
      </edu-table>
    </div>

    <edu-dialog
      :title.sync="dialogConfig.title"
      :visible.sync="dialogConfig.showDialog"
      @close="closeDialog(dialogConfig)"
      width="70%"
      height="650px"
    >
      <el-form
        ref="dialogForm"
        :model="dialogConfig.formData"
        :rules="dialogConfig.action === 'view' ? {} : dialogConfig.rules"
        label-width="230px"
        :disabled="dialogConfig.action === 'view'"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="用户ID" prop="accountId">
              <el-input v-model="dialogConfig.formData.accountId" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="用户名" prop="accountName">
              <el-input v-model="dialogConfig.formData.accountName" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="操作时间" prop="operateTime">
              <el-input v-model="dialogConfig.formData.operateTime" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="ip" prop="ip">
              <el-input v-model="dialogConfig.formData.ip" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="登录渠道" prop="channel">
              <DictSelect
                v-model="dialogConfig.formData.channel"
                :defaultOptions="options.channel"
                placeholder="请选择"
                clearable
                style="width: 100%;"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="登录终端" prop="terminal">
              <el-input v-model="dialogConfig.formData.terminal" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="版本" prop="version">
              <el-input v-model="dialogConfig.formData.version" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="操作类型" prop="operateType">
              <DictSelect
                v-model="dialogConfig.formData.operateType"
                :defaultOptions="options.operateType"
                placeholder="请选择"
                clearable
                style="width: 100%;"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="buttons">
        <template>
          <el-button @click="closeDialog(dialogConfig)">返回</el-button>
        </template>
      </span>
    </edu-dialog>
  </div>
</template>

<script>
import utils from "@/utils"
import mixins from "@/mixins";

import {
  queryLoginLogPageInfo
} from "@/api/LoginLogs"

const formData = {
  title: "",
  author: "",
  resume: "",
  content: "",
  image: "",
}
export default {
  mixins: [mixins],
  data() {
    return {
      queryParams: {
        condition: {},
        pageNum: 1,
        pageSize: 10,
        total: 0
      },
      tableList: [],
      dialogConfig: {
        title: "",
        showDialog: false,
        action: "add",
        formData: {},
        rules: {},
        fileList: []
      },
      options: {
        operateResult: [
          {
            name: "成功",
            code: "SUCCESS"
          },
          {
            name: "不成功",
            code: "FAIL"
          }
        ],
      },
    }
  },
  created() {
    this.initOptions()
  },
  methods: {
    async initOptions() {
      // 查询列表
      this.query()
    },
    // 查询
    async query() {
      let { returnObj } = await queryLoginLogPageInfo(this.queryParams)
      this.tableList = returnObj.list
      this.queryParams.total = returnObj.total
      this.queryParams.pageSize = returnObj.pageSize
    },
    // 重置
    reset() {
      for (var key in this.queryParams.condition) {
        this.queryParams.condition[key] = ""
      }
      this.queryParams.pageNum = 1
      this.queryParams.pageSize = 10

      this.query()
    },
    // 分页
    handleCurrentChange(row) {
      this.queryParams.pageSize = row.pageSize
      this.queryParams.pageNum = row.pageNum

      this.query();
    },
    closeDialog(dialog) {
      dialog.showDialog = false
      this.$refs["dialogForm"].resetFields();
    },
    openDialog(dialog) {
      dialog.showDialog = true
    },
    timeChange(date) {
      if (date) {
        this.queryParams.condition.beginTime = utils
          .dayjsIns(date[0])
          .format("YYYY/MM/DD hh:mm:ss")
        this.queryParams.condition.endTime = utils
          .dayjsIns(date[1])
          .format("YYYY/MM/DD hh:mm:ss")
      } else {
        this.queryParams.condition.beginTime = null
        this.queryParams.condition.endTime = null
      }
    },
    // 查看
    async view(row) {
      this.dialogConfig.title = "查看"
      this.dialogConfig.action = "view"

      // let { returnObj } = await queryOperateLogDetail(row.accountId)
      this.dialogConfig.formData = utils.clone(row)

      this.openDialog(this.dialogConfig)
    },
    
  }
}
</script>

<style lang="scss" scoped>
</style>
